/*
 * @lc app=leetcode.cn id=1109 lang=cpp
 *
 * [1109] 航班预订统计
 */

// @lc code=start
class Solution
{
public:
  vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n)
  {
    // 差分数组
    vector<int> d(n + 1);
    for (auto& booking : bookings) {
      d[booking[0] - 1] += booking[2];
      d[booking[1]] -= booking[2];
    }
    // 差分数组的前缀和即为原数组
    for (int i = 1; i < n; ++i)
      d[i] += d[i - 1];
    
    d.pop_back();
    return d;
  }
};
// @lc code=end
